<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>URL权限管理</title>
	<!--[if IE]>
	<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
	<![endif]-->
	<!-- Main Stylesheet --> 
	<link rel="stylesheet" href="<%=request.getContextPath()%>/css/style.css" type="text/css" />
	<!-- Your Custom Stylesheet --> 
	<link rel="stylesheet" href="<%=request.getContextPath()%>/css/custom.css" type="text/css" />
    <%@include file="/include/header.jsp" %>
    <script type="text/javascript" src="<%=request.getContextPath()%>/lib/jquery/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/function.js"></script>
    <script type="text/javascript">
	  	var path = "<%=request.getContextPath()%>";
	  	$(function(){
	  		loadUrls();
	  		loadAuths();
	  	});
	  	function loadUrls(){
	  		Mask.show();
	  		jQuery.ajax({
	  			url:path+'/protected/system/listForAssignUrl.action',
	  			dataType:'html',
	  			success:function(json){
	  				Mask.hide();
	  				$("#url_list").html(json);
	  			}
	  		});
	  	}
	  	function loadAuths(authname){
			var _authName = authname || '';
	  		Mask.show();
	  		jQuery.ajax({
	  			url:path+'/protected/system/listForAssignAuth.action?result=radio',
	  			dataType:'html',
	  			data:{"authName": _authName},
	  			success:function(json){
	  				Mask.hide();
	  				$("#auth_list").html(json);
	  			}
	  		});
	  	}
	  	function getURLCode(){
	  		var urlCodes = document.getElementsByName("urlCode");
			var urlCode = null;
			for(var i=0; i<urlCodes.length; i++){
				var _tmp = urlCodes[i];
				if(_tmp.checked){
					urlCode = _tmp.value;
					break;
				}
			}
			return urlCode;
	  	}
    	function show(){
			var urlCode = getURLCode();
			if(!urlCode){
				Alert("请选择URL！");
				return;
			}
			Mask.show();
			jQuery.ajax({
	  			url:path+'/protected/system/urlAuth_show.action',
	  			dataType:'json',
	  			cache:false,
	  			data: {"urlCode": urlCode},
	  			success:function(json){
	  				Mask.hide();
	  				setChecked("authCodes", json.data);
	  				setColor("authCodes", json.data);
	  			}
	  		});
    	}
    	<sec:authorize ifAnyGranted="ADMIN,URL_AUTH_RELATE">
    	function relate(){
    		var urlCode = getURLCode();
			if(!urlCode){
				Alert("请选择URL！");
				return;
			}
			var authCodes = document.getElementsByName("authCodes");
			var authCode = null;
    		for(var i=0; i<authCodes.length; i++){
    			if(authCodes[i].checked){
    				authCode = authCodes[i].value;
    			}
    		}
			Mask.show();
			jQuery.ajax({
	  			url:path+'/protected/system/urlAuth_relate.action',
	  			dataType:'json',
		  		type: 'post',
	  			data: {"urlCode": urlCode, "authCode": authCode},
	  			success:function(json){
	  				Ajax.callback(json);
	  			}
	  		});
    	}
    	</sec:authorize>
    </script>
</head>
<body>
<%@include file="/include/body.jsp" %>
	
<s:if test="flag">
	<!-- 显示操作成功 -->
	<script type="text/javascript">
		showTip("操作成功");
	</script>
</s:if>
<!-- Wrapper -->
<div class="wrapper">
	
     <table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr>
			<td width="40%" style="vertical-align:top;">
				<div class="content-box" id="query_area">
			    	<header>
						<h3>URL列表
	    				<span class="btn" onclick="loadUrls();">刷新</span>
			    		</h3>
					</header>
					<section style="width:95%;">
					    <div id="url_list" style="height:100%;">
				 			<%@include file="../../include/loading.jsp" %>
				 		</div>
					</section>
				</div>
			</td>
	 		<td width="10%" style="text-align:center;vertical-align:middle;">
			<sec:authorize ifAnyGranted="ADMIN,URL_AUTH_RELATE">
				<button class="btn btn-green" onclick="relate();"><span class="icon icon-ok"></span>提 交</button>
			</sec:authorize>
	 		</td>
	 		<td style="text-align:left;vertical-align:top;" width="50%">
	 		<div class="content-box" id="query_area">
		    	<header>
					<h3>权限列表
			    		<span class="btn" onclick="loadAuths();">刷新</span>
		    		</h3>
					<div>
			    		<span>
		    				<span>
		    					<input type="text" id="s_authname" />
		    					<button class="btn" onclick="loadAuths(getById('s_authname').value);">搜索</button>
		    				</span>
			    		</span>
					</div>
				</header>
				<section>
			    <div id="auth_list">
					<%@include file="../../include/loading.jsp" %>
				</div>
				</section>
			</div>
	 		</td>
	 	</tr>
	</table>
</div>
</body>
</html>